package service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import common.ServerResponse;
import dao.StudentMapper;
import entity.Student;
import service.IStudentService;

@Service 
public class StudentServiceImpl implements IStudentService{
	
	@Autowired
	private StudentMapper studentMapper;


	@Override
	public ServerResponse list(Integer page, Integer limit) {
		// 1、使用PageHelper插件设置分页
		PageHelper.startPage(page, limit);
		// 2、查询当前页的所有数据
		List<Student> list = studentMapper.pageList();
		//用PageInfo对结果进行包装
		PageInfo pageInfo = new PageInfo(list);
		Integer count = (int) pageInfo.getTotal();
		
		return ServerResponse.createSuccess("", count, list);
	}


	@Override
	public ServerResponse deleteById(Integer id) {
		int count = studentMapper.deleteById(id);
		if (count != 1) {
			return ServerResponse.createError("删除失败");
		}
		
		return ServerResponse.createSuccess("删除成功");
	}
	
}
